package everydaydo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class TeamName {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		InputStream ips = TeamName.class.getResourceAsStream("3.txt");
	    BufferedReader bd = new BufferedReader( new InputStreamReader(ips));
	    String line;
	    List<String> inf = new ArrayList<String>();
	    try {
			while((line=bd.readLine())!=null){
				inf.add(line.trim());
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				bd.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				ips.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		inf.remove(0);
		boolean begin =false;
		List<String> nameList = new ArrayList<String>();
		StringBuilder teamName = new StringBuilder();
		for(String s :inf){
			if(isNumeric(s)){
				if(begin){
					Collections.sort(nameList,new NameSort());
					teamName = new StringBuilder();
					for(String ss:nameList){
						teamName.append(ss);
					}
					nameList = new ArrayList<String>();
					System.out.println(teamName.toString());
				}
				begin=true;
				nameList= new ArrayList<String>();
			}else{
				nameList.add(s);
			}
		}
		Collections.sort(nameList,new NameSort());
		teamName = new StringBuilder();
		for(String ss:nameList){
			teamName.append(ss);
		}
		nameList = new ArrayList<String>();
		System.out.println(teamName.toString());

	}
	public static boolean isNumeric(String str){
		char[] temp = str.trim().toCharArray();
		for(int i =0;i<temp.length;i++){
			if(temp[i]<48||temp[i]>57){
				return false;
			}
		}
		 return true;
   }

}
class NameSort implements Comparator<String>{

	public int compare(String o1, String o2) {
		return o1.compareTo(o2);
	}
	
}
